

const express = require('express');
const router = express.Router();

const sql = require('../db/index');


router.get('/category', async (req, res) => {
    let { page, pageSize } = req.query;
    let start = (page - 1) * pageSize;
    let [category] = await sql.query(`select * from cms_category limit ${start},${pageSize}`);

    res.send({
        code: 200,
        message: '获取成功',
        data: category
    })

});


router.post('/category/saveorUpdate', async function (req, res) {
    let { id, name, description, no, } = req.body;
    let mysql = '';
    console.log(id, name, description, no)
    if (id) {
        mysql = `update cms_category set name=${name},
            description=${description},no=${no} where id=${id}`
    } else {
        mysql = `insert into cms_category (id,name,description,no,paernt_id) values
        id,${name},${description},${no},null)`
    }
    res.send({
        status: 200,
        message: '操作成功',
        data: null,
        timestamp: new Date().getTime()
    })

});

module.exports = router;